

package com.example.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.example.dto.ItemSearch;
import com.example.dto.Orders;
import com.example.ishoopingcaffe.R;

/**
 * Category adapter
 * 
 *  @author: truonglt2
 * @version: 1.0
 * @since: Feb 28, 2014
 */

public class SearchAdapter extends ArrayAdapter<ItemSearch> {

	public Context context;
	public int resourceId;
	public ArrayList<ItemSearch> arrOrders = null;

	/**
	 * 
	 * Constructor
	 * 
	 *  @author: truonglt2
	 * @Since: Feb 28, 2014
	 * @throws:
	 */
	public SearchAdapter(Context context, int resource,
			ArrayList<ItemSearch> objects) {
		super(context, resource, objects);
		this.context = context;
		this.resourceId = resource;
		this.arrOrders = objects;
	}

	/**
	 * noi dung sua
	 * 
	 *  @author: truonglt2
	 * @since:Feb 28, 2014
	 */
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return arrOrders.size();
	}
	

	/**
	 * noi dung sua
	 * 
	 *  @author: truonglt2
	 * @since:Feb 28, 2014
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		ItemSearchHolder categoryHolder = null;
		if (row == null) {
			LayoutInflater inflater = ((Activity) context).getLayoutInflater();
			row = inflater.inflate(resourceId, parent, false);
			categoryHolder = new ItemSearchHolder();
			
			
			categoryHolder.txtTitle = (TextView) row
					.findViewById(R.id.txtTitle);
			
			row.setTag(categoryHolder);
		} else {
			categoryHolder = (ItemSearchHolder) row.getTag();
		}

		// set information for item
		ItemSearch orders = arrOrders.get(position);
		categoryHolder.txtTitle.setText(orders.getTitle());
		
		
		
		return row;
	}

	/**
	 * class define widgets of view in listview comment
	 *  @author: truonglt2
	 *  @version: 1.0
	 *  @since: Mar 14, 2014
	 */
	private class ItemSearchHolder {
		TextView txtTitle;
	}
}
